/**********************************************************************\

 Copyright 2012 Diggory Blake

 This file is part of klip-engine

 This program is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation, either version 3 of the License, or
 (at your option) any later version.

 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with this program.  If not, see <http://www.gnu.org/licenses/>.

\**********************************************************************/
#pragma once

#include <unordered_map>
#include <unordered_set>

class kAnimation;
class kSprite;
class kSequence;

#include "kcommon.h"
#include "kcomponent.h"

class kAnimation : public kComponent {
private:
	std::unordered_set<kSequence*> _sequences;
	std::unordered_map<std::tstring, kSequence*> _namedSequences;

protected:
	void createSequence(kSequence* sequence);

public:
	void deleteSequence(kSequence* sequence);
	kSequence* getSequence(const std::tstring& name);
	void registerSequence(const std::tstring& name, kSequence* sequence);
	virtual void play(kSprite* sprite, kSequence* sequence) = 0;
	virtual void stop(kSprite* sprite) = 0;
	virtual void setSpeed(kSprite* sprite, float speed) = 0;
	inline void play(kSprite* sprite, const std::tstring& sequence) {
		play(sprite, getSequence(sequence));
	}
	inline void pause(kSprite* sprite) {
		setSpeed(sprite, 0.0f);
	}
	inline void resume(kSprite* sprite, float speed = 1.0f) {
		setSpeed(sprite, speed);
	}
};
